<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>手机通讯录</title>
    <link rel="stylesheet" href="/webjars/bootstrap/3.3.7/css/bootstrap.css">
    <script type="text/javascript" src="/webjars/jquery/3.4.1/jquery.js"></script>
    <script type="text/javascript" src="/webjars/bootstrap/3.3.7/css/bootstrap.css"></script>
    <script type="text/javascript" src="/webjars/vue/2.6.10/dist/vue.js"></script>
    <script src="/webjars/axios/0.19.0/dist/axios.js" type="text/javascript"></script>
</head>
<body>
<div id="vuebox">
    <div class="container" style="margin-top: 50px">
        <h3>在线通讯录</h3>
        <div class="row">
            <div class="col-md-6">
                <form class="form-inline" role="form" style="padding-left: 250px;">
                    <div class="form-group" style="padding-left: 20px;">
                        <label>查找联系人:</label>
                        <input type="text" v-model="cname">
                    </div>
                    <div class="form-group"  style="padding-left: 20px;">
                        <button type="button" class="btn btn-primary" @click="selectEntry(1)">查询</button>
                    </div>
                </form>

            </div>
            <div class="col-md-4 text-right">
                <a href="add_entry.html" @click.prevent="addPhone" class="btn btn-primary">新增电子图书</a>
            </div>
        </div>
        <br/>
    <table class="table table-striped">
        <thead>
        <tr>
            <th>序号</th>
            <th>姓名</th>
            <th>手机</th>
            <th>QQ</th>
            <th>Email</th>
            <th>地址</th>
        </tr>
        </thead>
        <tbody>
        <tr v-for="item in entries.data.list">
            <td>{{item.id}}</td>
            <td>{{item.cname}}</td>
            <td>{{item.mobile}}</td>
            <td>{{item.qq}}</td>
            <td>{{item.email}}</td>
            <td>{{item.address}}</td>
        </tr>
        </tbody>
    </table>
    </div>
    <br/>
    <div class="text-center">
        <ul class="pagination">
            <li v-show="entries.data.hasPreviousPage">
                <a href="#" @click.stop="selectEntry(entries.data.prePage)">&laquo;</a>
            </li>
            <li v-for="i in entries.data.navigatepageNums" :class="{active:entries.data.pageNum==i}">
                <a href="#" @click.stop="selectEntry(i)">{{i}}</a>
            </li>
            <li v-show="entries.data.hasNextPage">
                <a href="#" @click.stop="selectEntry(entries.data.nextPage)">&raquo;</a>
            </li>
        </ul>
    </div>

    <!--添加的模态框-->
    <div class="modal" id="mymodal">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" @click="hideModal()" type="button">&times;</button>
                    <div class="modal-title">
                        <p>添加联系人</p>
                    </div>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal" role="form">
                        <input type="hidden" v-model="new_entry.id">
                        <div class="form-group">
                            <label for="cname" class="col-sm-2 control-label">姓名</label>
                            <div class="col-sm-10">
                                <input v-model="new_entry.cname" id="cname" type="text" class="form-control" placeholder="请输入联系人姓名">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="mobile" class="col-sm-2 control-label">手机</label>
                            <div class="col-sm-10">
                                <input v-model="new_entry.mobile" id="mobile" type="text" class="form-control" placeholder="请输入联系人手机">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="qq" class="col-sm-2 control-label">QQ</label>
                            <div class="col-sm-10">
                                <input v-model="new_entry.qq" id="qq" type="text" class="form-control" placeholder="请输入图书摘要"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="address" class="col-sm-2 control-label">地址</label>
                            <div class="col-sm-10">
                                <input v-model="new_entry.address" id="address" type="text" class="form-control" placeholder="请输入qq">
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button class="btn btn-default" @click="hideModal()">关闭</button>
                    <button class="btn btn-primary" @click="savePhone">保存</button>
                </div>
            </div>
        </div>
    </div>

</div>
</body>
<script type="text/javascript">
        var vm=new Vue({
            el:"#vuebox",
            data:{
                entries:{},
                cname:"",
                pageNum:"1",
                new_entry:{
                    cname:"",mobile:"",qq:"",address:""
                },
                addphone:""
            },
            methods:{
                selectEntry:function (pageNum) {
                    axios.get("/sele",{params:{pageNum:pageNum,cname:this.cname}}).then(res=>{
                        this.entries=res.data;
                        this.pageNum=pageNum
                    })
                },
                addPhone:function () {
                    $("#mymodal").modal('show');
                },
                hideModal:function () {
                    $("#mymodal").modal('hide')
                },
                savePhone:function () {
                axios.post("/add",this.new_entry).then(res=>{
                    this.addphone=res.data;
                    if(this.addphone.result=="success"){
                        alert("添加成功!")
                        this.selectEntry(this.pageNum);
                    }else{
                        alert(this.addphone.message);
                    }
                    this.hideModal();
                })
                }
            },
            mounted(){
            this.selectEntry(this.pageNum);
            }
    })
</script>
</html>